<!-- SSLの場合 -->
@if(app('env')=='production')
	<link rel="stylesheet"
		  href="{{ secure_asset('/css/goods_detail.css') }}">
	<script src="{{ secure_asset('/js/jquery-3.3.1.min.js') }}"></script>
	<script src="{{ secure_asset('/js/goods_detail.js') }}"></script>
@else
	<!-- SSLではない場合 -->
	<link rel="stylesheet" href="{{ asset('/css/goods_detail.css') }}">
	<script src="{{ asset('/js/jquery-3.3.1.min.js') }}"></script>
	<script src="{{ asset('/js/goods_detail.js') }}"></script>
@endif @extends('layouts.system_common') @section('content')
	<script>
        var stock_time = "{!! Config::get("const.stockTime") !!}";
	</script>
	<div class="breadcrumbs_container">{{Breadcrumbs::render('customer.goods_stock_inquiry','') }}</div>

	<div id="">
		<div id="stock_detail_container">
			<div id="detail_goods_image_container">
				<div id="detail_stock_image_item">
					<div id="detail_stock_new_mark_item" class="new_mark_item">new!</div>
					<img id="detail_stock_image" src="{{$goodsImage}}" class="attachment-335x335 size-335x335" alt="">
				</div>
			</div>

			<div id="stock_goods_info_container">
				<div><p>商品名: {{$goodsDetail[0]->goods_name}}</p>
					<p>商品価格: {{$goodsDetail[0]->price}}+税</p></div>
				<div>
					<span id="forward_countdown"></span>
				</div>
			</div>
		</div>
		<div id="stock_info_container">
			<div> ◎ = 51以上　 ○ = 16 ~ 50 15以下は実数にて表示されております。</div>

			@foreach($houseList as $value)
				<div id="stock_items_container">
					<div id="detail_stock_image_item2" style="width: 136px;">
						<div id="detail_stock_new_mark_item2" class="new_mark_item">new!</div>
						<img id="detail_stock_image2" src="{{$goodsImage}}" class="attachment-335x335 size-335x335"
							 alt="" style="width: 110px;height: 110px">
						<div>{{$value[0]->color_name}}</div>
					</div>
					<div>
						<table>
							<tr>
								<th class="stock_tbl_th"></th>
								@foreach($value as $val)
									<th class="stock_tbl_th">{{$val->size_name}}</th>
								@endforeach
							</tr>
							<tr>
								<td class="stock_tbl_td">在庫状況</td>
								@foreach($value as $val)
									<td class="stock_tbl_td">{{$val->style}}</td>
								@endforeach
							</tr>
							<tr>
								<td class="stock_tbl_td">ご注文数</td>
								@foreach($value as $val)
									<td class="stock_tbl_td">
										<input class="lyx_goods_info" type="number" value=""
											   data-goods_model_id="{{$val->goods_model_id}}"
											   data-size_name="{{$val->size_name}}"
											   data-color_name="{{$val->color_name}}"
											   data-price="{{$goodsDetail[0]->price}}">
									</td>
								@endforeach
							</tr>
						</table>
					</div>
				</div>
			@endforeach
            <?php echo csrf_field(); ?>

		</div>
		<div id="stock_button_container">
			<button id="other_goods_btn" type="button"
					class="pure-button pure-button-primary button_normal">カートに入れて他の商品を見る
			</button>
			<button id="order_btn" type="button"
					class="pure-button pure-button-primary button_normal">カートに入れてご注文へ
			</button>

		</div>
	</div>


	<script>
        $(function () {
            var goods_id = '{{$goodsDetail[0]->goods_id}}';
            var goods_name = '{{$goodsDetail[0]->goods_name}}';

            $("#other_goods_btn").on('click', function () {
                addToCart(1);
            })

            $("#order_btn").on('click', function () {
                addToCart(2);
            })


            function addToCart(type) {
                var postData = [];
                $('.lyx_goods_info').each(function () {
                    var num = $(this).val();
                    var goods_model_id = $(this).data('goods_model_id');
                    var size_name = $(this).data('size_name');
                    var color_name = $(this).data('color_name');
                    var price = $(this).data('price');
                    if (num > 0) {
                        var g_info = {
                            goods_id: goods_id,
                            goods_name: goods_name,
                            goods_model_id: goods_model_id,
                            size_name: size_name,
                            color_name: color_name,
                            goods_num: num,
                            price: price
                        };
                        postData.push(g_info);
                    }
                })
                if (postData.length == 0) {
                    layuiTopMsg('商品の数を追加してください');
                } else {
                    console.log(postData);
                    dataToCat(postData, type);
                }
            }


            function dataToCat(data, type) {

                var token = $('input[name="_token"]').val();

                hdAjax({
                    url: "{{url('customer/goods_to_cat')}}",
                    data: {goodsList:data,_token:token},
                    type: 'post',
                    success: function (retData) {
                        if (retData.code == 1001) {
                            if (type == 1) {
                                successAlert('買い物車に加入して成功する', 'cart_buy');
                            } else {
                                successAlert('買い物車に加入して成功する', 'goods_stock_wear?goodsId=' + goods_id);
                            }
                        }
                    }
                })
            }


        })
	</script>
@endsection
